#ifndef PACKETH
#define PACKETH

#include <string>
#include "ByteStream.h"

struct PacketInt1
{
    PacketInt1(){}
    PacketInt1(int value) {
        b = value + 32;
    }

    int Value() const {
        return b - 32;
    }
    unsigned char b;
};

struct PacketInt2
{
    PacketInt2(){}
    PacketInt2(int value) {
        b[0] = ((value >> 7) & 0x7F) + 32;
        b[1] = (value & 0x7F) + 32;
    }

    int Value() const {
        return ((b[0] - 32) << 7) + (b[1] - 32);
    }
    unsigned char b[2];
};

struct PacketInt3
{
    PacketInt3(){}
    PacketInt3(int value) {
        b[0] = ((value >> 14) & 0x7F) + 32;
        b[1] =((value >>7) & 0x7F) + 32;
        b[2] =(value & 0x7F) + 32;
    }

    int Value() const {
        return ((b[0] - 32) << 14) + ((b[1] - 32) << 7) + (b[2] - 32);
    }
    unsigned char b[3];
};

struct PacketInt4
{
    PacketInt4(){}
    PacketInt4(int value) {
        b[0] =((value >> 21) & 0x7F) + 32;
        b[1] =((value >> 14) & 0x7F) + 32;
        b[2] = ((value >> 7) & 0x7F) + 32;
        b[3] = (value & 0x7F) + 32;
    }

    int Value() const {
        return ((b[0] - 32) << 21) + ((b[1] - 32) << 14) + ((b[2] - 32) << 7) + (b[3] - 32);
    }
    unsigned char b[4];
};

struct PacketInt5
{
    PacketInt5(){}
    PacketInt5(int value) {
        b[0] = ((value >> 28) & 0x7F) + 32;
        b[1] = ((value >> 21) & 0x7F) + 32;
        b[2] = ((value >> 14) & 0x7F) + 32;
        b[3] = ((value >> 7) & 0x7F) + 32;
        b[4] = (value & 0x7F) + 32;
    }

    int Value() const {
        return ((b[0] - 32) << 28) + ((b[1] - 32) << 21) + ((b[2] - 32) << 14) + ((b[3] - 32) << 7) + (b[4] - 32);
    }
    unsigned char b[5];
};

inline ByteStream NewPacket(int packetId) {
    return PacketInt1(packetId);
}

#endif // PACKETH

